import java.util.Scanner;

public class Demo4 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n = scan.nextInt();
        int[][] arr = new int[n][2000];

        int[] index = new int[n];//下标数组

        int sum = 0; //一共有多少个数

        while (scan.hasNext()) {
            String method = scan.next();
            switch (method) {
                case "add" :
                    int num1 = scan.nextInt();
                    arr[0][index[0]++] = num1;
                    sum++;
                    break;
                case "sync" :
                    int num2 = scan.nextInt();
                    if (index[num2] < sum) {
                        arr[num2][index[num2]] = arr[0][index[num2]];
                        index[num2]++;
                    }
                    break;
                case "query" :
                    int ret = Integer.MAX_VALUE;
                    for (int i = 0; i < n; i++) {
                        ret = Math.min(ret, index[i]);
                    }
                    System.out.println(ret);
                    if (ret == sum) {
                         return;
                    }
                    break;
            }
        }

//        scan.close();
    }
}
